package com.power.controller;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.repository.query.Param;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import org.springframework.web.bind.annotation.RestController;

import com.github.pagehelper.PageInfo;
import com.power.model.pojo.User;
import com.power.service.LoginService;

/**
 * 用户的登陆  添加  修改
 * 
 * @author Administrator
 *
 */
@RestController
@RequestMapping("/user")
public class LoginController {
	@Autowired
	LoginService ls;
	List<User> list;

	/**
	 * 登陆
	 * 
	 * @param name
	 * @param pwd
	 * @return
	 */
	@RequestMapping("/login")

	public User login(String name, String pwd) {

		User u = ls.login(name, pwd);
		System.out.println(name + "" + pwd);
		if (u != null) {
			System.out.println(u.toString());
			return u;
		}
		u = null;

		return u;

	}

	@RequestMapping("/all")
	public PageInfo<User> selectAll(@RequestParam("pageNo") Integer pageNo,
			@RequestParam("pageSize") Integer pageSize) {
		list = ls.selectAll(pageNo, pageSize);
		PageInfo<User> pager = new PageInfo<User>(list);
		return pager;
	}

	@RequestMapping("/add")

	public boolean addUser(@RequestBody User user) {
		if(ls.selectByuserName(user.getUname()).size()>0) {
			return false;
		}else {
			ls.addUser(user);
			return true;
		}
		
	}


	@RequestMapping("/where")
	public PageInfo<User> selectUserBynameAndIS(String name,Integer isstatus,Integer pageNo,Integer pageSize){
		list=ls.selectUserBynameAndIS(name, isstatus, pageNo, pageSize);
		PageInfo<User> pager = new PageInfo<User>(list);
		return pager;
	}
	@RequestMapping("/update")
	public void updateUser(Integer uid,Integer isstatus) {
		ls.updateUser(uid, isstatus);
	}
	@RequestMapping("/updateAll")
	public void updateUserAll(@RequestBody User user) {
		ls.updateUserAll(user);
	}

	@RequestMapping("/getByrid")
	public PageInfo<User> selectByRId(Integer rid,Integer pageNum,Integer pageSize){
		System.out.println(pageNum+"-----------"+pageSize);
		list=ls.selectByRId(rid, pageNum, pageSize);
		PageInfo<User> pager=new PageInfo<User>(list);
		return pager;
		

	}
	@RequestMapping("/selectRoleByxunjian")
	public List<User> selectRoleByxunjian(){
		return ls.selectRoleByxunjian();
	}
}

